﻿@model IEnumerable<ExpertSMS.Models.BillOfLadingProduct>
           @{
               ExpertSMS.Models.BillOfLading billOfLading = Model.FirstOrDefault().BillOfLading;
           }
<table>
    <tr>
        <th>สินค้า</th>
        <th>จำนวน</th>
        <th>หน่วย</th>
        <th class="right">ราคารวม</th>
        <th></th>
    </tr>
    @foreach (var item in Model)
    {
        <tr>
            <td>
                @Html.ActionLink(item.Product.Name,"Details","Products",new{id=item.ProductID},null)
            </td>
            <td class="right">@item.Quantity.ToString("n2")</td>
            <td>@item.Unit.Name</td>
            <td class="right">@item.Cost.ToString("n2")</td>
            @if (billOfLading.IsConfirmed)
            {
                <td></td>
            }
            else
            {
                <td>[ @Ajax.ActionLink("ลบ", "DeleteConfirmed", "BillOfLadingProducts", new { id = item.BillOfLadingProductID },
                new AjaxOptions { LoadingElementId = "loading", HttpMethod = "Get", UpdateTargetId = "productlist" }, null) ]</td>
            }
        </tr>
    }
    <tr>
        <th colspan="3">รวม</th>
        <th class="right">@Model.Sum(x => x.Cost).ToString("n2")</th>
        <th></th>
    </tr>
</table>
<br />
<div id="productdetails">
    @if (billOfLading.IsConfirmed)
    {
        <b>ได้รับการยืนยันและนำสินค้าเข้า Stock แล้ว</b>
    }
    else
    {
        
        @Html.Partial("_BillOfLadingProductDetails", Model.FirstOrDefault().BillOfLadingID)
        <br />

    }
</div>
@if (!billOfLading.IsConfirmed)
{
   using (Html.BeginForm("Confirm", "BillOfLadings"))
   {
            @Html.Hidden("id", billOfLading.BillOfLadingID)
            <input type="submit" value="ยืนยัน" /><span> (กรุณาตรวจสอบความถูกต้องก่อนยืนยัน) </span>
   }
}